const teacher = {
    state: {
        teacherDetailItem: [],   // 讲师的详情页 内容
        teacherDetailImgItem: [],// 讲师的详情页 头像
        teacherDetailClassItem: [],// 讲师的详情页 主讲课程
        teacherDetailEvaluate: [], // 讲师的详情页  学员评价 1
        teacherDetailEvaluate2: [], // 讲师的详情页  学员评价 2 
        teacherInviteItem: [], // 讲师的详情页 预约时间
        flag: 1,//是否被关注
    },
    mutations: {
        // 讲师的详情页 内容
        teacherDetail(state, data) {

            // console.log('aa',data.attr[2]);
            let aa = data.attr[2] === undefined ? data.attr[0].attr_name : data.attr[2].attr_name
            let dd = data.attr[3] === undefined ? data.attr[1].attr_value[0].attr_value_name : data.attr[3].attr_value[0].attr_value_name
            let bb = data.attr[2] === undefined ? data.attr[0].attr_value[0].attr_value_name : data.attr[2].attr_value[0].attr_value_name
            let cc = data.attr[3] === undefined ? data.attr[1].attr_name : data.attr[3].attr_name
            let intro = data.intro

            state.teacherDetailItem = {
                aa, bb, cc, dd, intro
            }
        },
        // 讲师的详情页 头像
        teacherDetailImg(state, data) {
            state.teacherDetailImgItem = data.teacher
            state.flag = data.flag
        },
        // 讲师的详情页 主讲课程
        teacherDetailClass(state, data) {
            state.teacherDetailClassItem = data
        },
        // 讲师的详情页  学员评价
        teacherComment(state, data) {
            state.teacherDetailEvaluate = data.data1
            state.teacherDetailEvaluate2 = data.data2
        },
        // 讲师的详情页 关注取关接口
        teacherFollow(state, data) {
            state.flag = data.flag
        },
        // 讲师的详情页 预约时间
        teacherInvite(state, data) {
            state.teacherInviteItem = data

            let date = new Date()

            date = 0 + String(date.getMonth() + 1) + (date.getDate() < 10 ? '0' + date.getDate() : date.getDate())

            data.weekDateList.map((el, index) => {
                let str = el[0] + el[1] + el[el.length - 3] + el[el.length - 2]
                // console.log(str);
                el = el[0] + el[1] + "/" + el[el.length - 3] + el[el.length - 2]

                // console.log(str, date)
                let obj = {
                    date: el,
                    flag: Number(str) < Number(date),
                }
                data.weekDateList[index] = obj
            })

            state.teacherInviteItem.weekDateList.forEach((item, index) => {

                switch (index) {
                    case 0:
                        item.day = "周一"
                        break;
                    case 1:
                        item.day = "周二"
                        break;
                    case 2:
                        item.day = "周三"
                        break;
                    case 3:
                        item.day = "周四"
                        break;
                    case 4:
                        item.day = "周五"
                        break;
                    case 5:
                        item.day = "周六"
                        break;
                    case 6:
                        item.day = "周日"
                        break;
                    default:
                        break;
                }
            })
        }
    },
    actions: {
        // 讲师的详情页 内容
        teacherDetail(context, id) {
            // console.log('vuex::::',id);
            this.$http.teacherDetail(id).then(res => {
                // console.log(res.data.data);
                context.commit("teacherDetail", res.data.data)
            })


        },
        // 讲师的详情页 头像
        teacherDetailImg(context, id) {
            this.$http.teacherDetailImg(id).then(res => {
                context.commit("teacherDetailImg", res.data.data)
            })
        },
        // 讲师的详情页 主讲课程
        teacherDetailClass(context, id) {
            this.$http.teacherDetailClass({
                limit: 10,
                page: 1,
                teacher_id: id
            }).then(res => {
                // console.log(res.data.data.list);
                context.commit("teacherDetailClass", res.data.data.list)
            })
        },
        // 讲师的详情页  学员评价
        teacherComment(context, id) {
            this.$http.teacherComment({
                limit: 10,
                page: 1,
                teacher_id: id
            }).then(res => {
                // console.log(res.data.data.comment.list.length !== 0);
                if (res.data.data.comment.list.length !== 0) {
                    let arr = res.data.data.comment.list[0].tag_content.split(',')

                    res.data.data.comment.list[0].tag_content = arr
                }

                context.commit("teacherComment", {
                    data1: res.data.data.comment.list,
                    data2: res.data.data.tag
                })
            })
        },
        // 讲师的详情页  关注
        teacherFollow(context, id) {
            this.$http.teacherFollow(id).then(res => {
                context.commit("teacherFollow", res.data.data)
            })
        },
        // 讲师的详情页 预约时间
        teacherInvite(context, id) {
            this.$http.teacherInvite({
                is_next: 0,
                teacher_id: id,
                week_day: 4
            }).then(res => {
                console.log(res.data.data);
                context.commit("teacherInvite", res.data.data)
            })
        }
    },
    modules: {}
}
export default teacher